package views;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: Артемка
 * Date: 01.12.13
 * Time: 20:23
 * To change this template use File | Settings | File Templates.
 */
public class MainFrame extends JFrame implements ActionListener {


    private List mainList;
    private JButton addModel, editModel, removeModel;  // я их сделал публичными, это правильно?
    private JRadioButton student, group;                // или нужно сделать get() для них?
    private JTextArea text;
    ButtonGroup bg;
    private JPanel panel;
    private GridBagLayout layout;


    public MainFrame() {

        layout = new GridBagLayout();
        panel = new JPanel(layout);

        addModel = new JButton("Добавить");
        editModel = new JButton("Изменить");
        removeModel = new JButton("Удалить");


        student = new JRadioButton("Студенты");
        group = new JRadioButton("Группы");

        bg = new ButtonGroup();

        text = new JTextArea("Режим работы:");

        mainList = new List();

        bg.add(student);
        bg.add(group);

        panel.add(mainList, new GridBagConstraints(0, 0, 3, 3, 0, 0, GridBagConstraints.CENTER,
                GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 270, 270));
        panel.add(addModel, new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 32, 5, 5), 10, 0));
        panel.add(editModel, new GridBagConstraints(3, 1, 1, 1, 0, 0, GridBagConstraints.SOUTH,
                GridBagConstraints.NONE, new Insets(0, 30, 5, 5), 11, 0));
        panel.add(removeModel, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.NORTH,
                GridBagConstraints.NONE, new Insets(0, 30, 5, 5), 17, 0));
        panel.add(text, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.CENTER,
                GridBagConstraints.NONE, new Insets(0, 30, 5, 5), 17, 0));
        panel.add(student, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.CENTER,
                GridBagConstraints.NONE, new Insets(50, 30, 5, 5), 17, 0));
        panel.add(group, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.CENTER,
                GridBagConstraints.NONE, new Insets(100, 20, 5, 5), 17, 0));

        add(panel);

    }

    public void addListenerForAdd(ActionListener listener) {
        addModel.addActionListener(listener);
    }

    public void addListenerForEdit(ActionListener listener) {
        editModel.addActionListener(listener);
    }

    public void addListenerForRemove(ActionListener listener) {
        removeModel.addActionListener(listener);
    }

    public JRadioButton getStudentRB(){
        return  this.student;
    }

    public int getListIndex(){
      return   mainList.getSelectedIndex();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //rewrite
    }
}
